<?php
/*
Primary Author: Alex Arey
Secondary: Derek Shue
Documentation: Cheng Yi
Updated: 12/10/2011
Module Description: The Application Acceptance module adds/finds/deletes Suggested Positions for internship requests from the database.
*/
class Application_Model_DbTable_ApplicationAcceptance extends Zend_Db_Table_Abstract
{

    protected $_name = 'APPLICATIONACCEPTANCE';

public function getSuggestedPositions($where)
    {
        $rows = $this->fetchAll($where);
        if (!$rows) {
            throw new Exception("Could not find row where $where");
        }
        return $rows->toArray();
    }
public function getSuggestedPosition($where)
    {
        $row = $this->fetchRow($where);
        if (!$row) {
            throw new Exception("Could not find row where $where");
        }
        return $row->toArray();
    }

    public function addSuggestedPosition($appid,$posid,$accepted)
    {
        $data = array(
        'APPID'=> $appid,
		'POSID'=> $posid,
		'ACCEPTED'=> $accepted,
        );
        $this->insert($data);
    }
    
    public function addUniqueSuggestedPosition($appid,$posid,$accepted)
    {
    	try{
    		$this->getSuggestedPosition('APPID = '. $appid.' and POSID = '.$posid);
    	}
    	catch(Exception $e){
		    $this->addSuggestedPosition($appid,$posid,$accepted);
		}
    }

    public function updateSuggestedPosition($appid,$posid,$accepted)
    {
        $data = array(
            'APPID'=> $appid,
			'POSID'=> $posid,
			'ACCEPTED'=> $accepted,
        );
        $this->update($data, ('APPID = '. (int)$appid .'and POSID = '.(int)$posid));
    }

    public function deleteSuggestedPosition($appid, $posid)
    {
        $this->delete('APPID =' . (int)$appid . ' and POSID = ' .(int)$posid);
    }



}
